﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Xtee.Core.Test.Service.Description
{
    /// <summary>
    /// 
    /// </summary>
    [TestFixture]
    public class DescriptionTests
    {

        /// <summary>
        /// 
        /// </summary>
        [TestCase("Calculator.wsdl")]
        public void ShouldLoadServiceDescription(string filename)
        { 
            var location = new WsdlLocation(@"..\..\..\..\Examples\Calculator\"+filename);
            var description = Services.Description.Description.Load(location);
            Assert.That(description, Is.Not.Null);
            Assert.That(description.Port, Is.Not.Null);
            Assert.That(description.Port.TargetNamespace.Namespace, Is.EqualTo("http://calculator.x-road.eu"));
            Assert.That(description.Schemas("http://calculator.x-road.eu").Count(), Is.EqualTo(1));
            var port = description.Port;

            Assert.That(port.Operations.Count(), Is.EqualTo(4));
            var operation = port.Operations.First();
            Assert.That(operation.Name, Is.EqualTo("GetHistory"));
            Assert.That(operation.Version, Is.EqualTo("v1"));
            Assert.That(operation.Input, Is.Not.Null);
            Assert.That(operation.Input.Name, Is.EqualTo("HistoryRequest"));
            Assert.That(operation.Output, Is.Not.Null);
            Assert.That(operation.Output.Name, Is.EqualTo("HistoryResponse"));
            Assert.That(operation.Port, Is.Not.Null.And.SameAs(port));

            foreach (var operation1 in port.Operations)
            {
                Console.WriteLine(operation1);
            }
        }
    }
}
